let downloadFile_onoff=true
import store from '../../store'
//上传文件
function upload(file) {
	if(downloadFile_onoff){
		return new Promise((result,reject)=>{
			downloadFile_onoff=false
			uni.showLoading({
				title: '图片上传中...'
			});
			//console.log(uni.getStorageSync('baseUrl'));
			uni.uploadFile({
				url: uni.getStorageSync('baseUrl')+store.getters.api.GLOBAL_fileTemp_uploadFile, 
				filePath: file,
				name: 'file',
				header:{
					authorization:store.getters.userToken,
					'us': 'app'
				},
				success: (uploadFileRes) => {
					downloadFile_onoff=true
					let data=JSON.parse(uploadFileRes.data)
					if(data.code==200){
						result(data.data)
					}else{
						uni.showToast({
							title: data.msg,
							icon:'none'
						});
						reject()
					}
					uni.hideLoading();
				},
				fail() {
					uni.hideLoading();
					downloadFile_onoff=true
					reject()
				}
			});
		})
	}
}

module.exports = {
	upload,
}
